package me.luger.project.fof.controller.admin;

import me.luger.core.dao.nutz.entity.page.DataTableRequest;
import me.luger.core.mvc.controller.BaseController;
import me.luger.core.mvc.entity.Result;
import me.luger.core.mvc.interceptor.oplog.OpLog;
import org.nutz.lang.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import me.luger.project.fof.service.BenchmarkPriceService;
import me.luger.project.fof.entity.BenchmarkPrice;

import java.util.List;

/**
 * BenchmarkPrice controller
 */
@Controller
@RequestMapping("/private/fof/benchmarkPrice")
public class BenchmarkPriceController extends BaseController {

    private String viewBasePath = "/admin/modules/benchmarkPrice/";

    @Autowired
    private BenchmarkPriceService benchmarkPriceService;

    @RequestMapping(value = "",name = "BenchmarkPrice列表页面")
    public ModelAndView index(){
        return btlView(viewBasePath + "index");
    }

    @RequestMapping(value = "data",name = "获取BenchmarkPrice列表")
    @ResponseBody
    public Object data(@RequestBody final DataTableRequest dataTableRequest){
        return benchmarkPriceService.data(dataTableRequest);
    }



    @RequestMapping(value = "delete",name = "删除BenchmarkPrice接口")
    @ResponseBody
    public Object delete(String[] ids){
        benchmarkPriceService.delete(ids);
        return Result.success("delete success");
    }

    @RequestMapping(value = "/detail/{id}",name = "获取BenchmarkPrice详细信息接口")
    public ModelAndView detail(@PathVariable("id") Integer id){
        BenchmarkPrice benchmarkPrice = benchmarkPriceService.fetchById(id);
        setAttr("benchmarkPrice",benchmarkPrice);
        return btlView(viewBasePath + "detail");
    }

    @RequestMapping(value = "add",name = "添加BenchmarkPrice页面")
    public ModelAndView add(){
        return btlView(viewBasePath + "add");
    }

    @RequestMapping(value = "addDo",name = "添加BenchmarkPrice接口")
    @ResponseBody
    @OpLog(name = "添加BenchmarkPrice",msg = "添加BenchmarkPrice")
    public Object adddo(BenchmarkPrice benchmarkPrice){
        try{
            benchmarkPrice = benchmarkPriceService.insert(benchmarkPrice);
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }

    @RequestMapping(value = "/edit/{id}",name = "更新BenchmarkPrice信息页面")
    public ModelAndView edit(@PathVariable String id){
        BenchmarkPrice benchmarkPrice = benchmarkPriceService.fetchById(id);
        setAttr("benchmarkPrice",benchmarkPrice);
        return btlView(viewBasePath + "edit");
    }

    @RequestMapping(value = "editDo",name = "更新BenchmarkPrice接口")
    @ResponseBody
    public Object editDo(BenchmarkPrice benchmarkPrice){
        try{
            benchmarkPriceService.updateIgnoreNull(benchmarkPrice);
        }catch (Exception e){
            return Result.error();
        }
        return Result.success();
    }
}
